
/**
 * 
 */
/**
 * 
 */
/**
 * @author Administrator
 *
 */
package com.financing.wap.service.payment.baofoo.demo;

import com.financing.wap.service.payment.baofoo.util.HttpRequestUtil;
import com.financing.wap.service.payment.baofoo.util.SecurityUtil;
import com.financing.wap.service.payment.baofoo.util.rsa.RsaCodingUtil;



public class ServeService{
		
	/**
	 * 
	 * @param keyParam  需要加密的字符串
	 * @param  prikeyPath 秘钥路径
	 * @param  pwd  秘钥密码
	 * @param nokeyParam 明文参数 
	 * @return  返回加密字符串
	 * @throws Exception 
	 * 
	 * 
	 */	
	public static String getParam(String nokeyParam,String keyParam,String prikeyPath,String pwd) throws Exception{
		String RSAEcodeString =RsaCodingUtil.encryptByPriPfxFile(SecurityUtil.Base64Encode(keyParam), prikeyPath, pwd);
		String params = "%s&data_content=%s";		
		params = String.format(params, nokeyParam,RSAEcodeString);
		return params;
	}
	
	/**
	 * 方法功能： 检查数据进行转发
	 * @param postUrl  请求地址
	 * 
	 * @param request
	 *            请求数据
	 * @param publicKey  解密公钥
	 * @throws Exception
	 */
	public  static String post(String postUrl, String params) throws Exception{		
		String responseStr = HttpRequestUtil.sendHttpsPost(postUrl, params,"UTF-8").toString();		
		return responseStr;
	}
	
	public static String DeResponseStr(String respStr,String publicKeyPath) throws Exception{
		
		String deString = RsaCodingUtil.decryptByPubCerFile(respStr, publicKeyPath);
		
		return SecurityUtil.Base64Decode(deString);
	}
	
}